package com.ftt.product.controller;

import com.ftt.Util;
import com.ftt.product.model.Order;
import com.ftt.product.service.ProductService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@WebServlet("/getOrderInfo.do")
    public class OrderListServlet extends HttpServlet {
        @Override
        protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            doGet(req, resp);
        }
        @Override
        protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            Object obj = req.getSession().getAttribute("phone");
            System.out.println("电话号码为："+obj);
            if(obj == null){
                Util.writerData(resp,new ArrayList<>());
                return;
            }
            long phone = Long.parseLong(obj.toString());
            ProductService productServlet = new ProductService();
            List<Order> orderList = productServlet.getOrderList(phone);
            Util.writerData(resp,orderList);
        }
    }
